package inner;

import com.sun.scenario.effect.impl.sw.java.JSWBlend_SRC_OUTPeer;

class OuterClass2{
    //如果不想通过外部类对象来创建内部类对象，就可以把内部类创建成静态内部类
    public int data1 = 1;
    int data2 = 2;
    public static int data3 = 3;
    public void test(){
        System.out.println("out::test()");
    }
    /**
     * 1,如何获取静态内部类对象 -- OuterClass2.InnerClass2 i = new OuterClass2.InnerClass2();
     * 静态内部类当中不能访问外部类的非静态成员，内部类的非静态成员需要通过外部类的对象的引用才能访问
            如果非要访问，OuterClass2 outerClass2 = new OuterClass2();
                        System.out.println(outerClass2.data1);
     */

    static class InnerClass2{
        public int data4 = 4;
        int data5 = 5;
        public static int data6 = 6;

        public void func(){
            System.out.println("in::func");
            OuterClass2 outerClass2 = new OuterClass2();
            System.out.println(outerClass2.data1);

            //System.out.println(data1);
            //System.out.println(data2);

            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }
}

class Person{
    public int age = 1;
    public String name = "bit";

    public void show()//太麻烦了
    {
        System.out.println("姓名："+name+"年龄："+age);
    }

    //Generate -> toString() -> ok
    @Override // 和底层实现有关
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}

public class test2 {
    public static void main(String[] args) {
        Person person = new Person();
        System.out.println(person);
        person.show();//打印太麻烦了
    }

    public static void main2(String[] args) {
        Person person = new Person();
        System.out.println(person.age);
        System.out.println(person.name);
        System.out.println(new Person().age);//匿名对象
        System.out.println(new Person().name);//只能使用一次

        //匿名内部类
        new Person(){

        };
    }
    public void func(){
        //局部内部类
        class Inner{
            public void test(){
                System.out.println("fafadsafsadfdsafsa");
            }
        }

        Inner inner  =new Inner();
        inner.test();
    }

    public void func2(){
        //
        class Inner{
            public void test(){
                System.out.println("fafadsafsadfdsafsa");
            }
        }

        Inner inner  =new Inner();
        inner.test();
    }
    public static void main1(String[] args) {
        OuterClass2.InnerClass2 i = new OuterClass2.InnerClass2();
    }
}
